package com.lindroy.androidplayer.viewmodels

import androidx.lifecycle.MutableLiveData
import com.google.gson.annotations.Expose
import com.lindroy.androidplayer.logic.model.ArticleResp

/**
 * @author Lin
 * @date 2022/2/8
 * @function
 */
data class ArticleItemViewModel(
    val apkLink: String = "",
    val audit: Int = 0,
    val author: String = "",
    val canEdit: Boolean = false,
    val chapterId: Int = 0,
    val chapterName: String = "",
    var collect: Boolean = false,
    val courseId: Int = 0,
    val desc: String = "",
    val descMd: String = "",
    val envelopePic: String = "",
    val fresh: Boolean = false,
    val host: String = "",
    val id: Int = 0,
    val link: String = "",
    val niceDate: String = "",
    val niceShareDate: String = "",
    val origin: String = "",
    val prefix: String = "",
    val projectLink: String = "",
    val publishTime: Long = 0,
    val realSuperChapterId: Int = 0,
    val selfVisible: Int = 0,
    val shareDate: Long = 0,
    val shareUser: String = "",
    val superChapterId: Int = 0,
    val superChapterName: String = "",
    val tags: List<ArticleResp.Tag> = listOf(),
    val title: String = "",
    val type: Int = 0,
    val userId: Int = 0,
    val visible: Int = 0,
    val zan: Int = 0,
    @Expose(serialize = true, deserialize = false)
    var itemCLickListener: MutableLiveData<ArticleItemViewModel>? = null
) {
    //是否为置顶文章，默认为否
    val isTop: Boolean
        get() = type == 1 //type为1是置顶文章

    data class Tag(
        val name: String = "",
        val url: String = ""
    )

    fun onItemClick() {
        itemCLickListener?.postValue(this)
    }

    /**
     * 分享的文章作者为空，则显示分享者名称
     */
    val finalAuthor: String
        get() = author.takeIf { author.isNotBlank() } ?: shareUser
}